<template>
  <div>
    <div class="add" @click="add" v-if="(rightValue & 1) > 0">新增</div>
    <van-search class="info_search input_text" v-model="value" @search="onSearch" @clear="clearSearch" placeholder="搜索">
    </van-search>
    <div id="divDepart" class="all_dep" @click="userOrgChooseDialogShow = true">
      {{ OrgName }}
      <van-icon name="arrow-down" />
    </div>
    <van-list v-bind:finished="myFinished" v-model="myLoading" finished-text="没有更多了" @load="myOnLoad">
      <div v-for="(item, index) in myList" v-bind:key="index">
        <van-cell class="card">
          <div @click="openDetail(item)">
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/weather.png" />
                天气情况：{{ item.WeatherName }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_date.png" />
                日期：{{ item.MettingDate | formatDate }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_group.png" />
                部门：{{ item.OrgName }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_expert.png" />
                班次：{{ item.WorkFrequencyName }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_post.png" />
                班长：{{ item.Monitor }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_user.png" />
                轮值安全员：{{ item.DutyOfficer }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_user.png" />
                创建人：{{ item.CreateChnName }}
              </van-col>
            </van-row>
            <van-row>
              <van-col>
                <img class="icon" src="@/assets/Images/AppIcon/icon_list_date.png" />
                创建时间：{{ item.CreateDate | formatDate }}
              </van-col>
            </van-row>
          </div>
          <van-row>
            <van-col span="24">
              <div class="dep_btm" v-if="rightValue > 0">
                <div class="btm_item" v-if="(rightValue & 1) > 0 && (writeValue==100 || item.CreateUserName==userName) " @click="goPreWorkMetting(item.ID)">
                  <img src="@/assets/Images/AppIcon/icon_list_edit.png" alt="" />
                  <div class="mr-10">编辑</div>
                </div>
                <div class="btm_item" v-if="(rightValue & 2) > 0 && (writeValue==100 || item.CreateUserName==userName)" @click="del(item)" style="margin-right: 15px">
                  <img src="@/assets/Images/AppIcon/icon_delete.png" alt="" />
                  <div>删除</div>
                </div>
              </div>
            </van-col>
          </van-row>
        </van-cell>
      </div>
    </van-list>
    <user-org-choose-dialog :show.sync="userOrgChooseDialogShow" :showClear="true"  @callback="userOrgChooseCallback">
    </user-org-choose-dialog>
  </div>
</template>
<script>
import { gxPreWorkMettingList, delPreWorkMetting } from "@/api/gx";
import { List } from "vant";
import UserOrgChooseDialog from "@/views/components/department/departmentChooseDialog.vue";
import { getMenuByMenuCode } from "@/api/common";

export default {
  components: {
    UserOrgChooseDialog,
  },
  data() {
    return {
      userOrgChooseDialogShow: false,
      value: "",
      myList: [],
      myFilter: {
        page: 0,
        dataType: "List",
      },
      OrgName: "不限",
      OrgCode: "",
      loading: false,
      finished: false,
      myLoading: false,
      myFinished: false,
      DeptmentShow: false,
      rightValue: 0,
      userName :this.$store.state.userName
    };
  },
  created() {
    if (this.$route.params.OrgCode) {
      const OrgCode = this.$route.params.OrgCode;
      this.filter.page = 0;
      var conditions = [
        { IsTemp: false, Name: "OrgCode", Operator: "\u003d", Value: "" },
      ];
      conditions.forEach((item) => {
        item.Value = OrgCode;
      });

      this.filter.conditions = JSON.stringify(conditions);
      this.OrgName = this.$route.params.OrgName;
    }
    this.getMyList();
    this.getMenuByMenuCode();
  },
  methods: {
    // 新增班前会议
    add() {
      this.$router.push({ path: "/GxPreWorkMettingEdit" });
    },
    // 编辑班前会议
    goPreWorkMetting(ID) {
      this.$router.push({ path: "/GxPreWorkMettingEdit?id=" + ID });
    },
    del(item) {
      var vm = this;
      const that = this;

      that.$dialog
        .confirm({
          title: "询问",
          message: "您确定要删除该会议记录吗？",
        })
        .then(() => {
          var params = { id: item.ID };
          delPreWorkMetting(params).then((res) => {
            vm.$toast.success("删除成功！");
            that.getMyList();
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    onSearch() {
      var conditions1 = [];
      if (this.value) {
        conditions1.push({
          Name: "Monitor",
          DisplayName: this.value,
          Value: this.value,
          Operator: "like",
          DataType: "String",
        });
      }
      conditions1.push({
        Name: "OrgCode",
        DisplayName: "OrgCode",
        Value: this.OrgCode,
        Operator: "like",
        DataType: "String",
      });
      this.myFilter.page = 0;
      this.myFilter.conditions = JSON.stringify(conditions1);
      this.getMyList();
    },
    clearSearch() {
      this.myFilter = {
        page: 0,
        dataType: "List",
      };
      this.value = "";
      this.getMyList();
    },
    getMyList() {
      this.myLoading = true;
      gxPreWorkMettingList(this.myFilter).then((res) => {
        this.myLoading = false;
        if (!res.data.HasNextPage) {
          this.myFinished = true;
        }
        this.myList = res.data.Data;
        this.myFilter.page = res.data.PageIndex;
      });
    },
    myOnLoad() {
      this.myLoading = true;
      ++this.myFilter.page;
      list(this.myFilter).then((res) => {
        this.myLoading = false;
        this.myFilter.page = res.data.PageIndex;
        this.myList = this.myList.concat(res.data.Data);
        if (!res.data.HasNextPage) {
          this.myFinished = true;
        }
      });
    },
    openDetail(item) {
      this.$router.push({
        path: "/GxPreWorkMettingView",
        query: { id: item.ID },
      });
    },
    userOrgChooseCallback(data) {
      this.OrgCode = data.OrgCode;
      this.OrgName = data.OrgName || "不限";
      this.onSearch();
    },
    getMenuByMenuCode() {
      var me = this;
      getMenuByMenuCode("GxPreWorkMetting").then((res) => {
        me.rightValue = res.data ? res.data.RoleRightValue : 0;
        me.WriteLev = res.data?res.data.WriteLev:0
      });
    },
  },
};
</script>
<style lang="less">
.van-cell::after {
  border-bottom: 0px;
}
.info_search {
  padding: 10px;
  border-radius: 5px !important;
}
#divDepart {
  background-color: #ffffff;
  padding: 10px;
  text-align: center;
  margin-left: 10px;
  margin-right: 10px;
}
.dep_item {
  width: 100%;
  padding: 10px;
  background-color: #e8f1f8;
  color: #666;
}

.dep_name {
  font-size: 16px;
  color: #000;
}
.dep_sort {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  img {
    height: 15px;
    width: 15px;
    margin-right: 5px;
  }
}
.dep_btm {
  display: flex;
  justify-content: flex-end;
  line-height: 27px;
  .btm_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>